package cn.itcast.mq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 创建交换机并与队列进行绑定
 */
@Configuration
public class fanoutConfig {

    //创建一个交换机
    @Bean
    public FanoutExchange fanoutExchange(){
        return new FanoutExchange("itcast.fanout");
    }
    //创建队列一
    @Bean
    public Queue fanoutQueue1(){
        return new Queue("fanout.queue1");
    }
    //绑定队列一和交换机
    @Bean
    /**
     * 这里声明交换机参数的时候回去spring容器里面查找我们定义的交换机对象和fanoutQueue1队列
     */
    public Binding fanoutBinding1(FanoutExchange fanoutExchange,Queue fanoutQueue1){
        return BindingBuilder.bind(fanoutQueue1).to(fanoutExchange);
    }

    //创建队列二
    @Bean
    /**
     * 这里声明交换机参数的时候回去spring容器里面查找我们定义的交换机对象和fanoutQueue2队列
     */
    public Queue fanoutQueue2(){
        return new Queue("fanout.queue2");
    }

    //绑定队列一和交换机
    @Bean
    public Binding fanoutBinding2(FanoutExchange fanoutExchange,Queue fanoutQueue2){
        return BindingBuilder.bind(fanoutQueue2).to(fanoutExchange);
    }

    /**
     * 要是bean是队列的话，他会去帮我们在rabbitMQ中创建对应的队列
     */
    @Bean
    public Queue objectQueue(){
        return new Queue("object.queue");
    }



}
